// subcontract/Mine/mineTracks/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    aliyunServrBaseURL: getApp().config.aliyunServrBaseURL,//阿里云公共地址
    tabs: ['商品', '店铺'],
    activeIndex: 0,//选择的下标
    page: 1,//页码
    pagingState: false,//分页状态
    goodsList: [],//商品
  },
  onChange(event) {
    console.log(event);
    let index = event.detail.index
    this.setData({
      activeIndex: index,
      page: 1,//页码
      pagingState: false,//分页状态
      goodsList: [],//商品
    })
    if (index == 0) {
      this.goodsCollect()
    } else {
      this.shopFollowlists()
    }

  },
  /**店铺收藏列表 */
  async shopFollowlists() {
    let object = {
      page_no: this.data.page
    }
    if (!this.data.pagingState) {
      const { code, data } = await getApp().api.shopFollowlists(object)
      if (code == 1) {
        this.setData({
          goodsList: this.data.goodsList.concat(data.lists)
        })
        if (data.more != 1) {
          this.setData({
            pagingState: true
          })
          return
        }
        this.setData({
          page: (this.data.page * 1) + 1
        })
        console.log(this.data.page);
      }
    }
  },
  /**商品足迹 */
  async goodsCollect() {
    let object = {
      page_no: this.data.page
    }
    if (!this.data.pagingState) {
      const { code, data } = await getApp().api.goodsCollect(object)
      if (code == 1) {
        this.setData({
          goodsList: this.data.goodsList.concat(data.lists)
        })
        if (data.more != 1) {
          this.setData({
            pagingState: true
          })
          return
        }
        this.setData({
          page: (this.data.page * 1) + 1
        })
        console.log(this.data.page);
      }
    }
  },
  /** 跳转 */
  navigateTo(event) {
    let url = event.currentTarget.dataset.url
    console.log(url);
    wx.navigateTo({
      url,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.goodsCollect()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    let { activeIndex } = this.data
    if (activeIndex == 0) {
      this.goodsCollect()
    } else {
      this.shopFollowlists()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})